<script type="text/javascript">
    var row = document.getElementById('skFlgId').value;
    var ggTable = document.getElementById('ggTable');
    function addGgRow() {
        var newTr = ggTable.insertRow(-1);
        newTr.setAttribute('id','psk'+row);
        var newTd0 = newTr.insertCell(0);
        var newTd1 = newTr.insertCell(1);
        var newTd2 = newTr.insertCell(2);
        newTd0.innerHTML = '<td><input class="textInput" type="text" size="30" name="psk'+row+'"/></td>';
        newTd1.innerHTML = '<td><input class="textInput" type="text" size="30" name="psv'+row+'"/></td>';
        newTd2.innerHTML = '<td><a title="删除" target="ajaxTodo" class="btnDel" onclick="deleteGgRow(this)">删除</a></td>';
        document.getElementById('trLength').value = ggTable.rows.length-1;
        row++;
    }
    function deleteGgRow(obj){
        if($("#ggTable tr").length > 2){
            row--;
            $(obj).parent().parent().remove();
            document.getElementById('trLength').value = ggTable.rows.length-1;
        }else{
            alertMsg.error('该行不能删除！');
        }
    }
    var tssxTable = document.getElementById('tssxTable');
    var tssxRow = document.getElementById('spFlgId');
    function addTssxRow(){
        var newTr = tssxTable.insertRow(-1);
        newTr.setAttribute('id','ppk'+tssxRow);
        var newTd0 = newTr.insertCell(0);
        var newTd1 = newTr.insertCell(1);
        var newTd2 = newTr.insertCell(2);
        newTd0.innerHTML = '<td><input class="textInput" type="text" size="30" name="ppk'+tssxRow+'"/></td>';
        newTd1.innerHTML = '<td><input class="textInput" type="text" size="30" name="ppv'+tssxRow+'"/></td>';
        newTd2.innerHTML = '<td><a title="删除" target="ajaxTodo" class="btnDel" onclick="deleteTssxRow(this)">删除</a></td>';
        document.getElementById('spsTrLength').value = tssxTable.rows.length-1;
        tssxRow++;
    }
    function deleteTssxRow(obj){
        if($("#tssxTable tr").length > 2){
            tssxRow--;
            $(obj).parent().parent().remove();
            document.getElementById('spsTrLength').value = tssxTable.rows.length-1;
        }else{
            alertMsg.error('该行不能删除！');
        }
    }
</script>
<div class="pageContent">
    <form method="post" action="updateCpOne" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
        <div class="pageFormContent" layoutH="56">
            <input type="hidden" id="trLength" value="<%=sds.length%>" name="trleng"/>
            <input type="hidden" id="spsTrLength" value="<%=sps.length%>" name="spstrleng"/>
            <p>
                <label>SN：</label>
                <input type="hidden" id="cpId" value="<%=cp._id%>" name="pid"/>
                <input name="psn" type="text" size="30" class="required" value="<%=cp.sn%>"/>
            </p>
            <p>
                <label>产品名称：</label>
                <input name="pName" class="required" type="text" size="30" alt="请输入产品名称" value="<%=cp.pn%>"/>
            </p>
            <p>
                <label>产品型号：</label>
                <input type="text" class="required" name="pType" value="<%=cp.tp%>">
            </p>
            <p>
                <label>批  号：</label>
                <input name="pbn" class="digits" type="text" size="30" alt="请输入数字" value="<%=cp.bn%>"/>
            </p>
            <p>
                <label>出厂日期：</label>
                <input type="text" name="pcd" class="date" size="30" value="<%=cp.cd%>"/><a class="inputDateButton" href="javascript:;">选择</a>
            </p>
            <p>
                <label>部署地点：</label>
                <input type="text" size="30" name="pds" value="<%=cp.ds%>"/>
            </p>
            <p>
                <label>生产入库时间：</label>
                <input type="text" name="pisd" class="date" size="30" value="<%=cp.isd%>"/><a class="inputDateButton" href="javascript:;">选择</a>
            </p>
            <p>
                <label>入库质检人：</label>
                <input type="text" size="30" name="pisqp" value="<%=cp.isqp%>"/>
            </p>
            <p>
                <label>入库管理员：</label>
                <input type="text" size="30" name="piswa" value="<%=cp.iswa%>"/>
            </p>
            <p>
                <label>质保期：</label>
                <input type="text" size="30" name="pwar" value="<%=cp.war%>"/>
            </p>
            <p>
                <label>出库时间：</label>
                <input type="text" name="posd" class="date" size="30" value="<%=cp.osd%>"/><a class="inputDateButton" href="javascript:;">选择</a>
            </p>
            <p>
                <label>出库管理员：</label>
                <input type="text" size="30" name="poswa" value="<%=cp.oswa%>"/>
            </p>
            <p>
                <label>提货性质：</label>
                <select name="pna" class="required combox">
                    <option value="">请选择</option>
                    <option value="出售" selected>出售</option>
                    <option value="出租">出租</option>
                </select>
            </p>
            <p>
                <label>提货人：</label>
                <input type="text" size="30" name="pbp" value="<%=cp.bp%>"/>
            </p>
            <div class="divider"></div>
            <table id="ggTable" class="searchContent">
                <thead>
                <tr>
                    <th>规格名称（可选）</th>
                    <th>规格值（可选）</th>
                </tr>
                </thead>
                <tbody>
                <%var i = 1%>
                <%if(sds.length <= 0){%>
                    <tr id="psk<%=i%>">
                        <td>
                            <input type="text" size="30" name="psk<%=i%>" value=""/>
                        </td>
                        <td>
                            <input type="text" size="30" name="psv<%=i%>" value=""/>
                        </td>
                        <td>
                            <a title="添加行" class="btnAdd" onclick="addGgRow()">添加</a>
                        </td>
                    </tr>
                <% i++ %>
                <%}else{%>
                    <%sds.forEach(function(sd){%>
                        <tr id="psk<%=i%>">
                            <td>
                                <input type="text" size="30" name="psk<%=i%>" value="<%=sd.sk%>"/>
                            </td>
                            <td>
                                <input type="text" size="30" name="psv<%=i%>" value="<%=sd.sv%>"/>
                            </td>
                            <%if(i==1){%>
                                <td>
                                    <a title="添加行" class="btnAdd" onclick="addGgRow()">添加</a>
                                </td>
                            <%}else{%>
                                <td>
                                    <a title="删除" target="ajaxTodo" class="btnDel" onclick="deleteGgRow(this)">删除</a>
                                </td>
                            <%}%>
                        </tr>
                    <% i++ %>
                    <%})%>
                <%}%>
                </tbody>
            </table>
            <input type="hidden" name="skNameFlg" value="<%=i%>" id="skFlgId"/>
            <table id="tssxTable" class="searchContent">
                <thead>
                <tr>
                    <th>特殊属性名（可选）</th>
                    <th>特殊属性值（可选）</th>
                </tr>
                </thead>
                <tbody>
                <% var j = 1%>
                <%if(sps.length <= 0){%>
                    <tr>
                        <td>
                            <input type="text" size="30" name="ppk<%=j%>" value=""/>
                        </td>
                        <td>
                            <input type="text" size="30" name="ppv<%=j%>"/>
                        </td>
                        <td>
                            <a title="添加行" class="btnAdd" onclick="addTssxRow()">添加</a>
                        </td>
                    </tr>
                <%}else{%>
                    <%sps.forEach(function(sp){%>
                        <tr>
                            <td>
                                <input type="text" size="30" name="ppk<%=j%>" value="<%=sp.pk%>"/>
                            </td>
                            <td>
                                <input type="text" size="30" name="ppv<%=j%>" value="<%=sp.pv%>"/>
                            </td>
                            <%if(j==1){%>
                                <td>
                                    <a title="添加行" class="btnAdd" onclick="addTssxRow()">添加</a>
                                </td>
                            <%}else{%>
                                <td>
                                    <a title="删除" target="ajaxTodo" class="btnDel" onclick="deleteTssxRow(this)">删除</a>
                                </td>
                            <%}%>
                        </tr>
                    <% j++ %>
                    <%})%>
                <%}%>
                </tbody>
            </table>
            <input type="hidden" name="skNameFlg" value="<%=j%>" id="spFlgId"/>
        </div>

        <div class="formBar">
            <ul>
                <!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
                <li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
                <li>
                    <div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
                </li>
            </ul>
        </div>
    </form>
</div>
